import numpy as np
import matplotlib.pyplot as plt


class DataAnalyzer:
    def __init__(self, methods, func, dimension):
        self.__data = []
        for method in methods:
            curve = np.loadtxt(rf'results/{method}_func{func}_d{dimension}.txt')
            gBest = curve[-1]
            self.__data.append([method, gBest, curve])

    def convergence_curve(self):
        for data in self.__data:
            plt.plot(range(len(data[2])), data[2], label=f'{data[0]}, {data[1]:.2f}')

        plt.xlabel('Iterations')
        plt.ylabel('Fitness')
        plt.legend()
        plt.show()

    def score_curve(self, path=None):
        acc = np.loadtxt(rf'results/callso_func1_d100_c_score.txt')
        plt.plot(range(len(acc)), acc)
        plt.show()


m = ['callso', 'sdlso', 'llso', 'pso']
analyzer = DataAnalyzer(methods=m, func=5, dimension=100)
analyzer.convergence_curve()
analyzer.score_curve()
